// pages/shop/shop.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show:'false',
    str1:3, //店铺id 皇叔那边传过来的参数是shopid
    obj2: {
      //装店铺信息的对象
      name: "",
      phone: "",
      address: "",
      score: ""
    },
    typeArr:[],
    productArr:[],
    typeid:0 //分类id
  },
  

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      typeid:1,
      str1:options.shopid
    })
    this.searchShoptopName();
    this.searchWxTopShopMenu();
    
    
    this.searchWxShopComs();
  },
  showClick:function(e){
    let isShow = e.currentTarget.dataset['del'];
    this.setData({
      show: !this.data.show
    })
  },
  searchShopInfo:function(){

  },
  // 头部店铺信息渲染函数
  searchShoptopName:function(){     
    let that = this;
    wx.request({
      method:"post",
      url: 'http://47.104.142.216/TP/public/index.php/index/Shopsearch/searchShoptopName',//给函数传递服务器地址参数  
      data: {                        
        str:that.data.str1    
      },//给服务器传递数据，本次请求不需要数据，可以不填
      header: { 
        'content-type': 'application/json' // 默认值，返回的数据设置为json数组格式
      },
      success: function (res) {
        let res2 = res.data.result;
        console.log(res);
        that.setData({
          obj2:{
            name:res2.shop_name,
            phone:res2.shop_phone,
            address:res2.shop_address,
            score:res2.shop_score
          }
        })
        console.log(that.data.obj2)
      },
    });
  },
  // 微信小程序店铺菜单搜索
  searchWxTopShopMenu:function(){
    let that = this;
    wx.request({
      method:"post",
      url: 'http://47.104.142.216/TP/public/index.php/index/Shopsearch/searchWxTopShopMenu',//给函数传递服务器地址参数  
      data: {
       str:that.data.str1
      },
      header: {
        'content-type': 'application/json' // 默认值，返回的数据设置为json数组格式
      },
      success: function (res) {
        
        that.setData({
          typeArr:res.data
        })
        console.log(that.data.typeArr); 
      },
    });
  },
  // 搜索店铺商品函数
  searchWxShopComs:function(){
    let that = this;
    wx.request({
      method:"post",
      url: 'http://47.104.142.216/TP/public/index.php/index/Shopsearch/searchWxShopComs',//给函数传递服务器地址参数  
      data: {
        str:that.data.str1,
        typeid:that.data.typeid  
      },
      header: {
        'content-type': 'application/json' // 默认值，返回的数据设置为json数组格式
      },
      success: function (res) {
        that.setData({ 
          productArr:res.data
        })
        console.log(that.data.productArr)
      },
    });
  },
  sortClick:function(e){
    console.log(e);
    console.log(e.currentTarget.dataset['sortid']);
    this.setData({
      typeid:e.currentTarget.dataset['sortid'],
      show:false
    })
    this.searchWxShopComs();
  },
  sortAllClick:function(){
    this.setData({
      typeid:1,
      show:false
    })
    this.searchWxShopComs();
  },
  // 跳转商品详情
  gotoProduct:function(e){
    console.log(e.currentTarget.dataset.proid)
    let id = e.currentTarget.dataset.proid;
    console.log(id)
    wx.navigateTo({
      url: '../goods/goods?cid='+id,
    })
  }
  
})